#include <src/test/miscellaneous/stat/Analyzer_Memory_Leak_test.h>


		void Analyzer_Memory_Leak_test(){
			Analyzer_Memory m("begin memory loop");
			_CrtMemState p1;
			_CrtMemCheckpoint(&p1);
			std::cout << std::endl << "----start Analyzer_Memory_test---------------------" << std::endl ;
			{
				{
						typedef smart_ptr<std::vector<int>> ptr;
						std::vector< ptr > test_memory_1(2000);
						for (OS_size i = 0; i < 10; ++i) {
							{
								test_memory_1[100*i] = ptr(new std::vector<int>(10));
								Analyzer_Memory mi_1("first memory loop");
								for (OS_size j = 0; j < 10; ++j) {
									test_memory_1[100*i+10*j] = ptr(new std::vector<int>(10));
									Analyzer_Memory mj("first sub memory loop");
									for (OS_size k = 0; k < 10; ++k) {
										test_memory_1[100*i+10*j+k] = ptr(new std::vector<int>(10));
									}
								};
							};
							{
								test_memory_1[200*i] = ptr(new std::vector<int>(10));
								Analyzer_Memory mi_2("second memory loop");
								for (OS_size j = 0; j < 10; ++j) {
									test_memory_1[200*i+10*j] = ptr(new std::vector<int>(10));
									Analyzer_Memory mj("second sub memory loop");
									for (OS_size k = 0; k < 10; ++k) {
										test_memory_1[200*i+10*j+k] = ptr(new std::vector<int>(10));
									}
								};
							};
						};
				}
			};
			m.end();
			std::cout << m;
			m.clear();
			std::cout << std::endl << "deleting intermediary memory storing" << std::endl;
			std::cout << m;
			_CrtMemState p2;
			_CrtMemCheckpoint(&p2);
			_CrtMemState p3;
			if ( _CrtMemDifference( &p3, &p1, &p2) ) {
				std::cout << std::endl << "memory leak detected :" << std::endl;
				_CrtMemDumpStatistics( &p3 );
				#define _CRTDBG_MAP_ALLOC
				_CrtDumpMemoryLeaks();
				OS_DYNAMIC_CHECK(false,"The memory leak analyzer tool generates memory leak :)")
			};

			std::cout << std::endl << "----end Analyzer_Memory_test---------------------" ;
			std::cout << std::endl << "------------------------------------------------" << std::endl;
		};


